Refactored and cleaned up code
Make sure all tests run