properly free memory in destructors