write file and compress improved