Added check to ensure only non null collections are looped through.