added tests, found some bugs