Major refacturing, all tests passing