added more tests and cleaned up code