added more unit tests and fixed some bugs