First really working version with queues