Adding unit tests and cleaning up