framework clean up

As I am helping Xiaoyun fix regression test, I have found many places to fix.

I am splitting those changes into a few PRs for better review processes.