cleaned up code, added comments and removed old and test code