Remove global var, add test cases.