fixing bugs and adding more tests (not all pass)