factored training code into new file