patch 1 add a test case that current master will fail. patch 2 and 3 are preparation pathes patch 4 solve the problem patch 5 do a light refactor Thanks, Yuan