Fixed stage 1 to write scripts. Still working on stage 2