nit: suggest to move this function to the beginning of the function.