refactored process_queue