Refactoring, tests, WIP