Applying consistent naming scheme to globals, and marking locals as such...

Nothing but a bit of code grooming: Fixing naming inconsistency across globals and marking all the locals inside functions as local variables.

Regarding the naming inconsistency: most globals started with upper case but 'map' started with lower case and it was getting mixed with a local by the same name in one of the functions.