You could well be right, but with just that to go on, it's difficult to tell. What is Sw[] an array of? How is it populated?