The code appears to work well. However, I'm very new to Python and do not understand the code too well as it is. Can you help me be adding comments to the code that explain the steps in a little bit of detail? I feel like docstrings and type hinting might also help me understand the code better.