FIX: logic when dump to file; accelerate the speed