Change script code into psthcorrtype() function