Added error checking when writing out bytes to frame