Fixing some memory leak issues