modified select loop