replaced byte by byte pattern-matching with buffered input