solving tests and refactoring