Fixed the gradient issue
Fixed a wrong code line
Fixed another gradient issue