Fix bug in to_bytes.