refactoring ruby and rails