Move flag handling (-v, -h) and add flag test cases