tighten types, improve error printing, and fix an error in cdata