Use generics to get correct return type