Added freeing of memory