improved generic shell script