adding memory freeing