add protocol & refactor code