Added deconstructors and fixed memory leaks.