Refactoring; more helpful error messages