adapted code for training on server