More refactoring; working so far