Use generics to avoid raw types warning rather than suppressing the warning.
Refactored a bit to make testing a little less invasive.