Implemented memory freeing