Move selection drawing code to separate function and fix slowdowns in determining of selection color.

Closes #466 & #464.