Will work on refactoring this in a different PR