Added checks and function
oups... remove type -p debugs