some small tweaks
convert shell to perl, most steps converted