This could probably be a lot better now that generics exist :) https://www.youtube.com/watch?v=lXdk3N122A4