Some refactoring to use generics.