added some unit tests (and fixed some bugs)