Added error checking to the swap function.

More comments for select.