code refactoring of Ruby side