Refactoring and PostFlag function