added some tests, fixed some bugs