make the code generic

Signed-off-by: Liu Bo <liub.liubo@gmail.com>