update script and fix bugs