Many fixes and tweaks on command line scripts