make scope tracker more reliable to handle all edgecases