Added function call traversal and comments to logic