added error generation optimization