fix PrimEnvironment and more verbose errors