Code Refactor. Improve Code performance.

Signed-off-by: Pengcheng Bian <pbian@actuate.com>