Rework library loading, add better error reporting