fixing bug when writing out xyz