update code to be more idiomatic to ruby