Code cleaning, commenting and refactoring

* More comments
* Less spaghetti code
* Cleaner implementation of intrinsic.py