Fix chained permissions (Issue #2)

This is a full Pull Request with the test fixes from the previous pull request and a fix for the actual functionality.  The code should now function both as described in the documentation and as is written in the tests