Can we move this to separate function?

@mariash @ryantang