Fix a bug; add a test for it.