pretraining algorithm initially working