Major rewrite
Major rewrite part 2: All tests pass