Major refactor, comments, cleanup, testing
Almost done