Getopt and a number of small improvements