refactored code for Plaid backend.