Tweak some code and update testcase.

Signed-off-by: crynobone <crynobone@gmail.com>