You should never look at code and say "this should work". If it "should" work it would work. If it doesn't work, you definitely made a mistake. Poke every assumption one by one. Preferably with an interactive debugger.
This may seem obvious but when I was younger I used to spin out in frustration at bugs.
This may seem obvious but when I was younger I used to spin out in frustration at bugs.