fix invalid write