Based from a patch by Lee Schröder, with modifications by myself. CORE-10044 #resolve svn path=/trunk/; revision=75968