clean up code and try to fix unit tests