remove global var and simplify api