Continuation on gates refactoring.
Moved some packets into RPCs.
Part of #1880.
fixed style, #1880