Modified not to assume NULL as the initialising value.