What do you mean by: the first bits don't work for the next bits?
I assume you mean your modules dont interface together, and this is the case with many libraries i picked up from the forum, had to re-code a lot of my stuff to glue with it.
Its a real problem and there is no way around it, you may be 99% done with the project and realize a small issue at the end (something that didnt scale initially), and you end up re-coding everything.
Its only after hitting these issues one after the other I have a small bit of foresight to know what can or will go wrong.
The only advice I can give you is to take the problem and divide it into as small bits as you possibly can.
Solve all of these individually in separate projects with a clean interface, and test them as much as you can.
Then export them as libs and use them in your main project.