Some refactoring and an attempt to add identity plugin to index.js