Make SGD more generic.