Fixed memory leaks (hopefully)