Fix performance issue.
add some comment and clean code