Created a commandline script, made main a pure module
fixed minor bugs