Added write_register function.