Large refactor to support syncing to the backend