Converted scripts to functions