When you read something difficult, like a legal agreement, it's difficult to understand every word. But you read the whole thing first, then go back to understand the words.
Similarly, when you code something complicated, it's difficult to keep it bug free. Just keep doing it, finish what you're doing, note down the bugs, and go back and fix the bugs. Otherwise, you'll never see the big picture if you spend your time worrying about bugs.
After you've done it a few times, you'll make less and less bugs. If you've ever started with C or PHP, there was probably a time when you were making fatal errors due to forgetting semicolons... now you're experienced enough that you never worry about it.
If you haven't done so already, I highly recommend getting a bug tracker and a to do list for your projects. It's probably one of the most important things I've picked up from the programming.