refactor errors (lib)