Factor

replaces and fixes #2074