fix a crash bug, and optimize.