Fixed issues exposed by unit tests.