Fix bugs in gradient regression