finished aapi solution for multiple accounts