added more generic pretrain method