Greatly improved error handling.