Refactor for parsing flags