fixed a few memory leak issues