Errors handling refactored.