Bit tricky to refactor but you're right. Took a shot at it.