moving all script code in to controllers