Rewrite in ruby, and faster!