Some refactoring.

This commit makes some work over the lib's structure.