Fix a logic bug