I'll refactor this in a separate PR later today so it shouldn't stop this being shipped.