placed global variable inside a function and pass it as arguments
placed global variable to function and pass it as arguments