Fixed bugs found by testing.