Refactoring to improve error messaging.