Make use of IEnumerable.

Makes use of useful IEnumerable methods, also simplifies code a bit.