Fix bugs found from testing.