Fixing potential memory leak with reset()