handle buffer correctly