added freeing of memory