Create tests and refactoring