use bash builtin 'type' instead of 'which'

'type' is a builtin command in bash, which requires less overhead than running
'which', which is a distinct program usually (always?) implemented as a script