Fix bugs caught by tests. :)