Fix for Mantis 1172 from Andrew Plotkin