doesn't work correctly but writes to file