More robust handling of schemas

Fixes #240