fixes typo and refactoring.

Signed-off-by: Rack Lin <racklin@gmail.com>