Improve error reporting and loading external code