code re-organization + unit test with gtest

Signed-off-by: Hong Zhiguo <honkiko@gmail.com>