First steps. Some refactoring of my own original version.

Signed-off-by: Carlos Escribano Rey <carlos@markhaus.com>