make ruby code more idiomatic