added error-checking