Wave cruft. Replaced weird argument-parsing with getopt. Some more preliminary optimisations