How do you debug your code? If you don't at least do the following, you may be costing yourself a lot of time and effort.
1. find a way to reproduce the bug cheaply.
2. reduce the number of possible causes (refine the bug's surroundings / divide and conquer)
3. understand the bug, (why it caused it and not other symptoms)
Once you think you have it:
1. make the fix and prove that it fixed it.
2. consider side effects
3. adjust some thinking / proof against future similar error