Added more trace and debug logging