added more error handling.