Remove SGD code duplication.