Refactor tern.