Algorithm cleaned little bit, added lot of docstrings.
Refactoring of the prototype. Code is now much cleaner.