Add time helper and implement gradients
Don't divide by 0