Fixed several memory leaks