added error handling.
add error handling.