Bit of refactoring into more idiomatic style. Thanks to [jlj](https://github.com/joelittlejohn) for the review.