Rewrote the selection logic

Now the selection logic has been rewritten to finally allow for
dynamic selection of text.