Fix bugs revealed by the simplest of tests