Refactoring, tests updated