fixed memory bugs with selection state