Bugfix

Full bugfixing of the script complete, and it is running correctly.