Add part of the patch provided by sergeych.
See: #5478
Authored by: jruigrok 2007-09-17
Parent: [r6014]
Child: [r6016]