some parts of queue_process.php refactored