Refactored code for loading flags