Refactored and made the tests work