Refactoring adapter.js