Big cleanup, and command line interface implemented.