* Make the text selection code more defensive * format * Move validation to a method * Fix math * rename