cloned from @spul, minor mods to mirror