Replaced simple 'while True' with queue-based loop