split protocol related code to dedicated file