alternative approach for to_bytes method