adding tests and cleaning up code