Fixed: tests and refactoring