pi_main updated, serial handshake, flags