Replaced global variables with local ones