Refactorized code.
Adapted to the latest library changes.