Added some tests and cleaned up a lot from previous commit.