Updated SGD Code