Added memory freeing