fix for issue #3221

THis is my fix for the issue I reported. As far as I can see it doesn't break anything. Please let me know if there any specific tests I can carry out.