Refactor argument parsing and validation