fixing global var bug