refactor protocol and db