Fixed the two iterators in the sound manager.

While on it, removed some duplicated code and renamed a variable according
to the code guidelines.