Wrote the monadic wrapper functions to run the system. This needs some tidying and further thought.