add error messages, and switch file api to be using FILEs rather than fstreams