Added breath first search for determining the order to execute nodes