Refactor code and make syntax more Ruby-like.