More flexible and robust rate function definition