There are lots of TODOs in this file, please give me some comments, then I will continue to use promise pattern to optimize pref here and handle the `err` variables.