Where does the program's behavior start to differ from what you expect it to do? You should use a debugger or print statements to figure that out.