rewrote, simplified api, closes #1