Clean up redundant code.
Added another error page detection.