Code refactor, cleanup, and comments

Diff are a little hard to follow, but the tests all pass. Code is a little easier on the eyes now I think : )