Changed read to read number of bytes rather than rely on NULL terminated strings