Have you tried stepping through the code in a debugger to see what's failing?