restructured code, add Generic types