typo and fix
Optimize some parts of script