Updated code as best as possible

Getting this code working is a bit of a work in progress. Much of
the origional code was out of date and there are some other commits
that I pulled into this because the changes were usefull. I believe
that this is almost working correctly. The only thing that is still
failing is when the pull request is made. This is due to changes in
the GitHub api.