fixed some issues, tests pass