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.