added test for gradients, corrected gradients