Clean code and add docstrings

The following changes took place as cleaning measures:
    - Remove dead code
    - Remove excessive print statements
    - Add a branch_problem function with a global scope for the script