Move job processing into a separate function