cleaned up code, added some simple unit tests