Added pretraining function