Added check to ensure output queue is not empty