Check if null before trimming