Use the right generic type to reduce the amount of casts