WIP: Strict type-checking in the public API

A start for #110. Needs more tests and polishing.