Took a pass to clean up the code, fix memory leaks, convert tabs to spaces, and other little things.