turn on JS before checking redirects + refactoring