Move flag parsing to separate function