Fixed some inappropriate memeory deallocations.