Reapply a corrected version of the fix

It seems likely that the original fix was ok, but there were some debugging warning messages left in that were causing trouble. Those have been removed.