Adding pivot metadata caching and moving most of rest of library over to variadic LogicError/RuntimeError and DEBUG_ONLY.