More generics

Again mostly replacing raw collections used by their generic counterparts. Also removing some unused imports, changing raw comparators to generic ones, and other minor clarity improvements and simplifications.