Change script to join commands and fix some defects