updated code to write body