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


Former-commit-id: 698cb9bff9587a7bf1098fd72c5c8dd7646f82a4 [formerly 94c7d4e6c299be688940321c7d6459e0e8cf93a9]
Former-commit-id: 5423670063fc6c369b34e6e08593c07a62f4e210
gem/oq-engine,gem/oq-engine,gem/oq-engine,gem/oq-engine,gem/oq-engine