Bayesian inference in dynamic models with latent factors