implemented Mem_Free and utility functions