begin rewrite in ruby