PAT_Advanced code