make the selection more save by checking selection.rangeCount before accessing getRangeAt