Minor API improvements and refactoring.