Lots of work tidying up code, along with fixes to autoguider logging.