fix scope lookup functions to look in correct scopes