As much as top-down design is the best way to solve a problem, it is not very friendly to code implementation.
Write your code bottom up. In other words, write and test the subroutines that depend on nothing else first. This way, you can test these low-level subroutines and functions without worrying whether the problem is with them or some other subroutines. Next, write subroutines that only rely on tested subroutines.
This bottom up approach makes it easier to spot problems. Although it is possible that you may have forgotten some test cases, and a “tested” subroutine turns out to be faulty, this method still makes it easier to localize bugs.
If you encounter a bug, make sure the lowest-level subroutines are correct first, even if the symptoms point to a high-level subroutine (that calls other subroutines).