made a toByteArray() method for messages