SELECT tests and bugfixes