fixed variable used before declared