changed write method