Initial massive refactoring.

Prefer now uses promises.