Clean up cpf code a bit