Handle nulls properly in redirect function