Refactored and commented
Now it works again