bug fixes and tests.