tweak _begin and _end to pass this into inner function, so target of this assignment can be controller from outside