fix variable scope