Implemented Question 3 in a more readable way (using a ExpandedNode object and a HashMap to store expanded objects)