code copy from PH repo of the survey modaule