Add some docs for how type inference works. Also a couple minor code changes to rearrange or rename for better clarity.