refactored rails scripts