fix variable scope error