Please debug the problem with a debugger --- as to check where the logic is breaking.