added tests
fixed some bugs
fixed a typo