Moved the running logic into lib.rs (is still called as before from main.rs)
Config options are now all stored in a single struct (that can be built up from the command line options as before, or parsed from strings - which is needed when calling from Python)