fixed error in ExactError function and changed the code's layout