On definable groupoids and imaginaries