Tidy the code up a little pending rebase and upstream pull request