Improved version of the script

Rewrited the file