Improve error management (rc in functions)