Began cleaning up and refactoring code