Rewrited whole code with pattern and still in progress