Added gradient check code