Refactoring of ruby code