Code refactoring.

Move all global variable to local struct.