fixed variable declaration at wrong scope