various shell script improvement and fixes.