Initial work on basic failover support.
Some refactoring to make the API more understandable.
Simplify some API bits.