Write ctx_send and fix compile errors and warnings