Improved use of Java generics in collections

Just added appropriate type parameters to collections and changed some iterators to for-each loops for shorter code.