fixed clobbering issues with macros and hardcoded functions (more pushing and popping of scopes, ensure that there is always a valid scope when there should be.)