Restructured logic to use templates and almost comlpeted input for the new types