Refactored FlagService.