Code refactoring on the viewErrors page to avoid potential errors