Fix for Mantis 1221 from Andrew Plotkin