replaced queue.length call with queue.size() call