Fixed global var issue