Bit more logging and some code cleanup