Working on a refactor of this code block. I'm going to submit that in a separate PR.