Tidy up, add logging, print output to stdout