Fixed various bugs causing test failures.

548u, 5i