Add generic types and fix invocations of static members.

Add generic types to reduce the amount of unsafe casts and warnings.
Replace invocations of static members from instances with class.