Proper way to remove a callback from a document

Can you provide a complete minimal example that demonstrates what you are seeing that is unexpected, that can be run and investigated? It’s really hard to say much about partial code. It looks reasonable at a glance.