exit -1 isn't compatible with some shells
use "if status" instead of checking $?
several minor fixes