Fixes nested ability conditions in issue #859

Fixes nested ability conditions and incorporates the test condition from Pull Request 45bc237