code cleanup

* added statehandler functions for each of the state cases in the state
machine to compact the switch
* added g_ prefix to global variables
* made deltatime global
* commented everything
* refactored the names of a bunch of functions too