fix bug, tests pass