Add debug output, use it to fix problem