move purity function to utils.