Jobs.py refactoring

Refactored codes to reduce code duplication for jobs.py. No functionality changes.