optional check gradient added