Made casts type safe