Fixes #1007 stackoverflow in AndResultSet

Don't merge yet. I would like to have a test that verifies good functioning.