fixed bugs, added tests and usage documentation