Separated training routine from general network code.