fix SelectionRange and clean up