Modified write method.