add training function, need to test it