fixing toBuffer problem