refactored flag upload