Do you think we can move this function to somewhere in utils or a better place?