Refactor to allow different types of redirects.