Changed the script, added functions