Fix conversion typo
Fix typos
Name more variables
Make some variables local
Name more variables
Fix conversion typo
More local variables and a bit of refactoring