Trapping errors to stop the page from breaking