changed some of the code to use more idiomatic ruby syntax.