Fixing some memory leaks