Remove code duplication in argument parsing