fix bugs with `which`