rewrite, refactor using ruby coding style