Bug fix on write