LZW   refactored