Comments and cleanup
Switch foldl to foldr
Add some untested code, for more efficient handling of outer quantifiers