see parser.cpp for queue traversal algo