Fixed error accumulation function