If you want a possible object orientated solution, the code looks ripe for refactoring using the chain of responsibility design pattern.
FinnNk
- 5.8k
- 3
- 30
- 33