Pathwise optimality in stochastic control