move Buffer.isBuffer out of loop