Refactor codes into same if condition

Signed-off-by: Clark Wang <clark.wangs@gmail.com>
Refactor tests and codes

Signed-off-by: Clark Wang <clark.wangs@gmail.com>
Refector tests and codes

1. remove error
2. prune tests

Signed-off-by: Clark Wang <clark.wangs@gmail.com>