Using the appendix two simple model to fix the bug
The bug is trivial

Next time when debugging try to watch the result and  find some trends to utilize.