Refactored for #158.