added a new version using the changes from Brendans pull request