Global cleanup

Renamed some global variables, added comments.