support for count() and multiple relationships, also cleanup