Fix for Mantis 1091 from Andrew Plotkin