Added tests and fix tenant filtering.