bug fix on global program and code refactoring