fixing global variable issue