I feel there is a fair amount of technical debt which is making it more difficult to understand the code and address bugs and enhancements.
It's probably time to address this.
To start with I will create a draft PR with proposed refactors for review/comment.