added error detection