If you want us to fix your code for you, you have to post it (completely, of course), including all information about available memory, disk space etc, so we can get a picture where your bottlenecks are.
Keep in mind that this is a forum where tips and hints are given, and code snippets for particular problems. Reworking a whole design is consultant work and usually done for money.