added tests, fixed bugs, etc