Extract selection into its own module.

Hi, I ripped the selection hack out into its own module and cleaned up a little bit in the process.