Factor out local and remote client