working serial version. estimated error using variance estimater is not implemented yet