Fixed bugs, working script.