We keep getting back to the memory issue. I think you have learned a lot and would suggest starting over, completely from scratch. Throw your code away.
I realize this sounds crazy but taking this approach has worked for me several times. I figure out all the things I get wrong and when i start over, it fits together better. Good luck!
ron