Fixed my very first "buffer underflow" since the 90s , refactored and improved code readability, doc comments, etc. I'm quite happy with the current status.
Next step: adding the logging system and removing all the debugging prints. Maybe I'll continue later, who knows...