added a test and fixed some bugs. yay!