Corrected code to work for all types of data using generics right