Hi,
I am guessing something is wrong with your end routine only.
Just put a break point in end routine and in DTP filter just keep a single document, and then use simulation (run DTP) to debug.
Go step by step using F5 key and see is it behaving correctly.
Please paste the code, if possible so we can have a look, also the expected behavior.
Thank-You.
Regards,
VB