Closes #3511730 Copy of !22 with tests. Pushed separately just in case, to not be PITA in !22 in case tests are WIP for it