Moved gradient clipping to cost