refactoring ruby script