move some logic from adapter.js to index.js