merging remote and local impl
some reorg for clarity