Refactor to use getopt