Made buffering more stable, small code refactor