fixed global var bug for code