fixed some bugs, all unit tests pass now!