move env stuff into top-level header, add function object for throwing exceptions