Using the queue to prevent consuming too much memory