refactor and file output in utf-8
solve 012