Fixed memory leak issues