fixed some memory leak issues i believe