Added check for implicit variable declaration to fix test cases for global declarations. Added check for function declaration to examine upper scope for identifiers. Cleaned up some unused variables.

Changed code style to align with original style.
Merge remote-tracking branch 'origin/master'