Fixed the toBytes method