Fix for Mantis 1197 from Andrew Plotkin