applied iangilman\'s patch