ADDED ERROR DETECTION