Added gradient functions.