Added generics, changed iteration