Improve and refactor createJob function.