fix invalid writes