Fix a strange bug with a function running twice despite being checked