Fix bugs in select.
Fix more bugs in select the popped up as a result of refactoring.