Fix a bug that was shown up by writing a test