Trying to handle generics, but the compiler gives a segmentation fault