implemented gradient