replace routine for error estimation