Fixed invalid write by 1 error