More refactoring to easily switch between binary and JSON backends
Fix tests