Finish refactoring, tests not working yet