add more type safety

Inspired by my review of @camillescott 's #216 pull request