Enhanced queue.py