implement select loop