Fixing one permission check bug and adding some debug output in hope to find that bug.