Code improvement
Top-level scripts are improved:
- functions are documented using docstrings
- type hints are added
- comments are improved
- code duplication is reduced by extracting some functions into a new file (CAP_utils)
- some error handling is added here and there
- code is simplified here and there
Scripts were tested, their results did not change.