I made some changes to the original pull request to remove complexity which I believe was not needed.