Added flag handling to main.