Done refactor. Need more tests.
Tests. Still need more, though.