Rewrite it in ruby