Bit of code fixup and add some loggin