Fixed selection bug. Added comments.
Added first regression tests. More to come.