using getopt, more command options
remove unused functions, tidy up