Logging and general tidy-up