Adds a queue container

Adds a queue/FIFO container, considering the feedback given in #2361.
Also, this entire function could probably be better expressed in a "do checks, return false if fails, until we reach the end". The current code is long and complicated, and not even efficient (why don't you `break` ?)