implemented gradients, TODO: check for errors

Transpose errors could crop up easily.