The first error is thrown, since you are now returning three objects/values:
return model, val_acc_history, train_acc_history

The second is thrown, because epoch is indeed not defined in validate, so you could pass it as an argument to the function.