updated a portion to include error handling