Remove unnecessary casts and null checks