Add tests for boolean functions and tighten up error handling
Simplify implementation from pull request #728