Fix broken getopt command line parsing
Clean up code