Fix a bad optimization refs #3586