refactoring, fixing some generics issues.