Huge refactoring and little bug fix in generic parameters