Refactor and mix codes