Refactor codes in transformer