proto-shell: move more core to handler.c