fixed variable scope issue