Rewrote using GNU getopt