declared n at start for better structure.