Using an HashSet rather than a Stack to keep track of nodes in wait list