moved tasks to endJob function