Check that messages array is not null before processing