Adding code for estimating bg model.