added error checking for redirection