Improve scripts
Fix bug in script