implement openScope/closeScope function