Bug fix: writing out of allocated memory.