Refactor serial interface