Applied API
Refactorized code, now it´s working properly