Application of requested modifications to Pull request #3141

This is to apply the modifications requested by randx to pull request #3141 which fixed issues discussed in issue #2012