Added some debug messages, moved around some functions - nothing exciting
Removed some old variables that I don't use for anything
Fixed the 'close' function
Cleaned up memory leaks, as well as other minor code cleanups