added some error analysis