fix query error handling and update minor comments