reorganize to automatically count the number of jobs