Additions to patch supplied by Tim Wilkes

Final Credit for the pull request to me