improve callback logic