Arranged script code to be more manageable