Try tobytes method for speedup.