partial refactor of network encoder