change the method to free memory