cleanup and small optimizations
factoring tenant key out