added tests, fixed errors