added error simulation code (versioned out)