fix error when contents is  nil