Created a safe memory deletion feature and fixed some bugs