minor optimization: use class to replace anonymous function, which can reduce the memory usage and initializing time.