rewrite of which.sh