made script path detection smart about errors