Preliminary bug fixing for write logic.