Added display of errors. Refactoring.