changing calculation of training error
rewrote async code