refactor to work in a multi-tenant style