refactor and add code pass for direct optimization of ELBO