Maybe fix issue calculating length from buf