NEW: Use DB row for job status and refactor the sql statements