Better logging and sort out tests, bit of tidy.