Refactored work with api