fixed some double free issues