Cleaned up code
Reverted unnecessary check in first loop
Clarifying node to baseNode while resolving scope