This could probably use some tests, but I'm not really sure what exactly should be tested. Will leave a review with a few comments on things that might need a different approach. Closes #7032.