Improved the text selection handling and some cosmetic amends.