Refactor and test code, add new utility functions, refs #51755