simplified some script logic