Cleaned up locking of jobs and added test case