refactors into idiomatic ruby