Improved script and resolved bugs.