Fixed bug in queue calculation