fix scope issues in callback functions