bug fixes in new code and tests that revealed them