Fixed typo in variable decleration, see last commit

Please see the last commit for the list of fixes/changes