Refactored to be more Ruby-idiomatic.