Fix bug in queue implementation causing crash