Correct schema handling, fixes #486 and #487
Merged with upstream.