backporting @mariomc's new callback