Move redirect code to onload