Fix a bug and test for it