Fix bug with compound Q objects. Add test for it.