Fixed bugs and now this script should run properly.