Fixing bugs, all unit tests succeed now. Need more tests.