improve external training function