[Master] Minor improvements

Some type hints and decrease of cyclomatic complexity.

This is just a proposal. Fell free to close. :)