Refactored so it will actually compile