Implement early stopping on validation set