lots of improvements, tests pass