Code Refactoring and add Global variables