Removed global variable and replaced by proper function arguments.