Added write mode function.