Add generic type parameters.

This change set allows us to remove a lot of unnecessary type-casting, by declaring instances with correct type parameters.