added test, fixed some bugs