Remove unchecked ID manipulation calls.
Rewrite nextjob() to correctly check error conditions.
Fix various compiler warnings.