Added toBuffer and fromBuffer