fixed the bug that wrongly use write().