Updated with error handling.