Fixed bugs in JobQueue, and added checks and unit tests