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.
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss. Register now and lock in 2025 pricing—just $495!