fix some type issues when writing to memory