major refactor of consensus and other code