replace which with check function