Fixed bugs and added a commandline interface.