Added check for errors before redirecting. Before, notices and warnings occurring before a redirect wouldn't register in debug mode.