added more tests and cleaned up some code