Fixes

Fixed scope of some variables
Replaced tabs with spaces