i have trouble seeing the logic in code sometimes
This is common, don't worry about it. Understanding code that you're not familiar with is much like trying to understand how someone else thinks. Usually getting a walkthrough of that entire portion (not the entire system as it may make your head explode if the entire system is big enough) of the system architecture helps a great deal. Once you understand the overarching solution, the logic in the specific code chunks can start to make quite a bit more sense.
It sounds to me like you need practice at system architecture. The next time you're tackling a problem, forget about the code. First, fully understand the problem that you're dealing with. Of course, if you don't fully understand a given problem, engineering a solution will be difficult at best. Next, take a look to see if there's an implementation for that problem readily available (OS), or if there's a design pattern that can be applied to it (Wikipedia has a decent list). If not, then start desiging a solution (still not even thinking about the code - all of this should be abstract design).
Once your design is done, then start coding.
Of course, studying design patterns and algorithms (and algorithm design/analysis) will most definitely help you in your conquest here, but practice really is just as important (whether you actually implement your designs or not is beside the point).
Doing this enough times will help spur that abstract problem solving thinking that you seem to be having issues with.
And don't ever forget: No matter how good you think you get at this, there will always be someone (or a number of someones) who are quicker/better/brighter than you. Use them to help you get better - don't let their abilities frustrate you.