Simplify handlePurls function