added function to check and auto-clear flag