Cleanup: Moved write_dispatcher to own subroutine