refactor encoder sending loop