converted few of the scripts to functions