Reduce repetition in code for undefined identifiers

Both of the modified codepaths concern undefined identifiers. The first specifically handles identifiers found in the global scope; the second handles all others. The two paths differ in three ways, only one of which appears to be a legitamate difference. (The second is an unecessary conditional statement, and the third is actually a bug that likely originated from the duplication of logic.)

This patch addresses the two illigitamate differences and introduces a simple branch for the one legitimate difference. I've split each into a separate commit to help document my rationale. All tests pass for each commit.

I think that the remaining difference (`if (!funct["(global)"])`) is another candidate for removal, but removing it (if appropriate) would require additional refactoring, so it may be best to leave it for some future pull request.