Program works but has a lot of memeory leaks