added error condition checking