Make masterfd optional and improve the protocol