new prepareSelector function to avoid code repetition