pull request

Here is an updated and fixed pull request. I merged the upstream into my repo, to fix  a few issues. I will make sure to fetch the master and merge it with my repo before I make a pull request. I don't want my fork to get to far off the mark of the master.