Factor out first_existing function.