Lot's of refactor

Signed-off-by: Rock Lee <insfocus@gmail.com>