Fix redirection bugs.
Add jsDoc.