Fix a bug reported on Stackoverflow.