Added logging and debug code.