Efficient Formulation And Implementation Of Ensemble Based Methods In Data Assimilation