change some script to functions