null checking and edits to xml writting format