Passed all tests and refactored a little bit