added better debug logging