Moved count for n outside closure