Fix bugs based on tests.