adding gradient function