Moved queue code to While loop.