[WIP] Refactor of SGD code to use only one call to plain_sgd/average_sgd

This code also makes all methods private and extracts the multiprocessing function into a helper function.