fixed three memory leaks, improved handling of command line arguments