Adding gradients and minor fixes

Feat @Larry006