making sure all memory is freed when program exits