improved the API for the callbacks & fixed a tricky crash with a workaround from stackoverflow