Fixing a bug in set/clear flag functions