added more error handling