Fixing almost all of the memory leaks, except for the ops