More than a little surprised this works. Definitely needs refactoring.