Sorry I should have noted that I was aware this needed a refactor, your suggestion makes the most sense.