changes to the count query and the update relationships function