Removing intential memory leaks, program runs fine again