Fixed flag not being cleared