refactored code to make it testable
refactored code to make it testable


Former-commit-id: 94c7d4e6c299be688940321c7d6459e0e8cf93a9
gem/oq-engine,gem/oq-engine,gem/oq-engine,gem/oq-engine,gem/oq-engine