Work in progress: refactor error handling.