algorithm now takes errors into account.