General code cleanup

Begin code cleanup. Should probably add more comments above certain functions and classes.