rewriting in ruby