wrote a bunch of tests and fixed some bugs