finshed changing print to write. needs test